/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lifxue.jqda.ui.autofield;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author lifxue
 */
public class DefaultCompletionFilter implements CompletionFilter {

    private List<String> listAll;

    public DefaultCompletionFilter() {
        listAll = new ArrayList<String>();
    }

    public DefaultCompletionFilter(List<String> templist) {
        listAll = templist;
    }

    @Override
    public ArrayList filter(String text) {
        ArrayList list = new ArrayList();
        String txt = text.trim().toLowerCase();
        int length = txt.length();
        for (int i = 0; i < listAll.size(); i++) {
            Object o = listAll.get(i);
            String str = o.toString();
            if (length == 0 || str.startsWith(txt)) //输入内容与记录前端比较；如果是空格，就在列表中显示所有
            {
                list.add(o);
            }
        }
        return list;
    }
}
